//
//  MeBizQutoeCell.m
//  ZITHER
//
//  Created by weixin on 2018/11/22.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MeBizQutoeCell.h"

@implementation MeBizQutoeCell



-(void)setModeTyep2:(MyEnquiryListDataEndNewModel *)modeTyep2{
    _modeTyep2 = modeTyep2;
    self.WatchVInfo.modeTyep2 = modeTyep2;
    self.BottomTipe.modeTyep2 = modeTyep2;
}

-(void)upModel:(MyEnquiryListDataNewModel*)modeTyep1{

    self.WatchVInfo.modeTyep1 = modeTyep1;
    self.MeBizQutoeV.modeTyep1 = modeTyep1;
    self.BottomTipe.modeTyep1 = modeTyep1;
    
    NSString *str1 = modeTyep1.acceptPriceCount;
    if (![str1 isEqualToString:@"0"]) {
        self.hidden = NO;
        self.endView.lab.text = [NSString stringWithFormat:@"结束%ld个报价",self.indexEnd];
    }
}

///正在询价中
-(void)setModeTyep1:(MyEnquiryListDataNewModel *)modeTyep1{
    _modeTyep1 = modeTyep1;

    [self upModel:modeTyep1];
    
}

//询价结束
//-(void)setModeTyep2:(MyEnquiryListDataEndNewModel *)modeTyep2{
//    _modeTyep2 = modeTyep2;
//    self.alpha = 0.3;
//    self.labTakein.text = modeTyep2.acceptPriceCount;
//    NSString *strImage = [NSString stringWithFormat:@"%@%@",RootUrlImage,modeTyep2.imageDefault];
//    [self.imageWatch sd_setImageWithURL:[NSURL URLWithString:strImage]];
//    self.labTitle.text = modeTyep2.brandNameNative;
//    self.labSubTitle.text = modeTyep2.goodName;
//
//
//    [self.viewBizinfo mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(0);
//    }];
//    [self.viewTips mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(0);
//    }];
//    self.viewBizinfo.hidden = YES;
//    self.viewTips.hidden = YES;
//
//    [self.view1 mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(0);
//    }];
//    [self.labReceive mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(0);
//    }];
//    [self.labSubReceive mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(0);
//    }];
//    [self.view2 mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.labSubTitleTakein.mas_right).offset(5);
//    }];
//    self.view1.hidden = YES;
//    self.labReceive.hidden = YES;
//    self.labSubReceive.hidden = YES;
//}



-(void)setBizQutoeType:(BizQutoeCell)type{
    switch (type) {
        case BizQutoeCellDef://    BizQutoeCellBtnTips,//底部带按钮提示
            [self upMasonryBizQutoeCellDef];
            break;
        case BizQutoeCellREnd:// 已结束询价入口顶部展示
            [self upMasonryBizQutoeCellREnd];
            break;
        case BizQutoeCellBtnTips:// 已结束的询价列表展示
            [self upMasonryBizQutoeCellBtnTips];
            break;

        default:
            break;
    }
}

-(void)upMasonryBizQutoeCellDef{
    
    [self.endView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.height.mas_equalTo(0);
    }];
    self.WatchVInfo.backgroundColor = [UIColor randomColor];
    [self.WatchVInfo mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.endView.mas_bottom).offset(10);
        make.height.mas_equalTo(80);
    }];
    
    [self.MeBizQutoeV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.WatchVInfo.mas_bottom).offset(10);
        make.height.mas_equalTo(60);
    }];
    
    [self.BottomTipe mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.MeBizQutoeV.mas_bottom).offset(0);
        make.height.mas_equalTo(60);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    
    self.endView.hidden = YES;
    self.WatchVInfo.hidden = NO;
    self.MeBizQutoeV.hidden = NO;
    self.BottomTipe.hidden = NO;

}

-(void)upMasonryBizQutoeCellREnd{
    [self.endView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.height.mas_equalTo(50);
    }];
    
    [self.WatchVInfo mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.endView.mas_bottom).offset(0);
        make.height.mas_equalTo(80);
    }];
    
    
    [self.MeBizQutoeV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.WatchVInfo.mas_bottom).offset(10);
        make.height.mas_equalTo(0);
    }];
    
    [self.BottomTipe mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.MeBizQutoeV.mas_bottom).offset(0);
        make.height.mas_equalTo(0);
        make.bottom.equalTo(self).offset(15);
    }];
    
    
    self.endView.hidden = NO;
    self.WatchVInfo.hidden = NO;
    self.BottomTipe.hidden = YES;
    self.MeBizQutoeV.hidden = YES;

}

-(void)upMasonryBizQutoeCellBtnTips{
    
    [self.endView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.height.mas_equalTo(0);
    }];
    
    [self.WatchVInfo mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.endView.mas_bottom).offset(0);
        make.height.mas_equalTo(80);
    }];
    
    
    [self.MeBizQutoeV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.WatchVInfo.mas_bottom).offset(10);
        make.height.mas_equalTo(0);
    }];
    
    [self.BottomTipe mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.MeBizQutoeV.mas_bottom).offset(0);
        make.height.mas_equalTo(60);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    self.endView.hidden = YES;
    self.WatchVInfo.hidden = NO;
    self.BottomTipe.hidden = NO;
    self.MeBizQutoeV.hidden = YES;
}


-(void)setUI{
    [self addSubview:self.endView];
    [self addSubview:self.WatchVInfo];
    [self addSubview:self.MeBizQutoeV];
    [self addSubview:self.BottomTipe];
}

-(void)setMasonry{
    
    [self.endView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(17);
        make.right.equalTo(self).offset(-17);
        make.top.equalTo(self).offset(0);
        make.height.mas_equalTo(50);
    }];
    self.WatchVInfo.backgroundColor = [UIColor randomColor];
    [self.WatchVInfo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(17);
        make.right.equalTo(self).offset(-17);
        make.top.equalTo(self.endView.mas_bottom).offset(0);
        make.height.mas_equalTo(80);
    }];
    
    [self.MeBizQutoeV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(17);
        make.right.equalTo(self).offset(-16);
        make.top.equalTo(self.WatchVInfo.mas_bottom).offset(10);
        make.height.mas_equalTo(60);
    }];
    
    [self.BottomTipe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(17);
        make.right.equalTo(self).offset(-17);
        make.top.equalTo(self.MeBizQutoeV.mas_bottom).offset(0);
        make.height.mas_equalTo(60);
        make.bottom.equalTo(self).offset(-20);
    }];
    

    
}

-(MeBizQutoeEndTipe *)endView{
    if (!_endView) {
        _endView = [[MeBizQutoeEndTipe alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _endView.backgroundColor = [UIColor randomColor];
    }
    return _endView;
}

-(MeBizQutoeWatchV *)WatchVInfo{
    if (!_WatchVInfo) {
        _WatchVInfo = [[MeBizQutoeWatchV alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _WatchVInfo.backgroundColor = [UIColor randomColor];

    }
    return _WatchVInfo;
}

-(MeBizQutoeV *)MeBizQutoeV{
    if (!_MeBizQutoeV) {
        _MeBizQutoeV = [[MeBizQutoeV alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _MeBizQutoeV.backgroundColor = [UIColor randomColor];

    }
    return _MeBizQutoeV;
}

-(MeBziQutoeBottomTipe *)BottomTipe{
    if (!_BottomTipe) {
        _BottomTipe = [[MeBziQutoeBottomTipe alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _BottomTipe.backgroundColor = [UIColor randomColor];

    }
    return _BottomTipe;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.viewBorder.clipsToBounds = YES;
    [self setBorderWithHiddem:YES Color:[UIColor colorWithHex:@"cccccc"] width:0.5 Radius:15];
        [self.viewBorder mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(10);
            make.left.equalTo(self).offset(15);
            make.right.equalTo(self).offset(-15);
            make.bottom.equalTo(self).offset(-5);
        }];
    self.backgroundColor = [UIColor randomColor];
    [self setUI];
    [self setMasonry];
}




- (NSString *)pleaseInsertStarTimeo:(NSString *)time1 andInsertEndTime:(NSString *)time2{
    // 1.将时间转换为date
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *date1 = [formatter dateFromString:time1];
    NSDate *date2 = [formatter dateFromString:time2];
    // 2.创建日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit type = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    // 3.利用日历对象比较两个时间的差值
    NSDateComponents *cmps = [calendar components:type fromDate:date1 toDate:date2 options:0];
    // 4.输出结果
    
    NSLog(@"%@",[NSString stringWithFormat:@"%ld",cmps.day]);
    return [NSString stringWithFormat:@"%ld",cmps.day];
}


@end
